package com.laikan.reader.bookfriend.activity;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.laikan.library.components.activitys.BasicActivity;
import com.laikan.library.utils.SPUtil;
import com.laikan.reader.R;
import com.laikan.reader.comment.APIProtocol;
import com.laikan.reader.core.utils.PublicUtil;

import java.util.ArrayList;

/**
 * 账户信息
 *
 * @author wx
 */
public class Account extends BasicActivity{

    private RelativeLayout rela_recharge;// 充值记录
    private RelativeLayout rela_consume; // 消费记录

    private RelativeLayout rela_notes; // 阅读券
    private RelativeLayout rela_vip; // VIP
    private RelativeLayout rela_grow; // 成长值
    private RelativeLayout rela_recommend; // 推荐票
    private RelativeLayout rela_gold; // 黄金联赛
    private RelativeLayout rela_change;// 切换账号
    private TextView money;
    private TextView notes_num;
    private TextView vip_num;
    private TextView grow_num;
    private TextView recommend_num;
    private TextView gold_num;
    private ImageView back_tv;
    private RelativeLayout back_layout;
    Drawable drawable_back_tv,drawable_right_jiantou;
    private ImageView reader_right,vip_right,grow_right,recommend_right,chongzhi_right,consume_right,change_right;
    /**
     * 从个人中心
     */
    private int moneys = 0;// K币
    private String pNotes;// 阅读券
    private String pVip;// VIP
    private String pGrow;// 成长值
    private String pRecommend;// 推荐票
    private String pGold;// 黄金联赛
    private boolean pPayAction;
    private ArrayList<Integer> payratio = new ArrayList<Integer>();
//    private TextView recharge_btn;

    @Override
    protected void assignViews() {
        setContentView(R.layout.account);
        rela_recharge = (RelativeLayout)findViewById(R.id.rela_recharge);
        rela_consume = (RelativeLayout)findViewById(R.id.rela_consume);
        rela_notes = (RelativeLayout)findViewById(R.id.rela_notes);
        rela_vip = (RelativeLayout)findViewById(R.id.rela_vip);
        rela_grow = (RelativeLayout)findViewById(R.id.rela_grow);
        rela_recommend = (RelativeLayout)findViewById(R.id.rela_recommend);
        rela_gold = (RelativeLayout)findViewById(R.id.rela_gold);
        rela_change = (RelativeLayout)findViewById(R.id.rela_change);
//        recharge_btn = (TextView)findViewById(R.id.recharge_btn);
        back_layout = (RelativeLayout) findViewById(R.id.back_layout);
        back_tv = (ImageView) findViewById(R.id.iv_back);
        money = (TextView)findViewById(R.id.money);
        notes_num = (TextView)findViewById(R.id.notes_num);
        vip_num = (TextView)findViewById(R.id.vip_num);
        grow_num = (TextView)findViewById(R.id.grow_num);
        recommend_num = (TextView)findViewById(R.id.recommend_num);
        gold_num = (TextView)findViewById(R.id.gold_num);

        reader_right = (ImageView)findViewById(R.id.reader_right);
        vip_right = (ImageView)findViewById(R.id.vip_right);
        grow_right = (ImageView)findViewById(R.id.grow_right);
        recommend_right = (ImageView)findViewById(R.id.recommend_right);
        chongzhi_right = (ImageView)findViewById(R.id.chongzhi_right);
        consume_right = (ImageView)findViewById(R.id.consume_right);
        change_right = (ImageView)findViewById(R.id.change_right);
    }

    @Override
    protected void initData() {
        SPUtil.putBoolean("switch_account", false);
        Intent intent = getIntent();
        moneys = intent.getIntExtra("money", 0);
        pNotes = intent.getStringExtra("notes");
        pVip = intent.getStringExtra("VIP");
        pGrow = intent.getStringExtra("grow");
        pRecommend = intent.getStringExtra("recommend");
        pGold = intent.getStringExtra("gold");
        pPayAction = intent.getBooleanExtra("payAction", true);
        payratio = getIntent().getIntegerArrayListExtra("payratio");

//        if (pPayAction) {
//            recharge_btn.setVisibility(View.VISIBLE);
//        }else {
//            recharge_btn.setVisibility(View.GONE);
//        }

        money.setText(moneys + "K币");
        notes_num.setText(pNotes + "阅读券");
//        if (pVip.equals("-1")) {
//            vip_num.setText("非会员");
//        }else {
//            vip_num.setText(pVip + "");
//        }
        grow_num.setText(pGrow);
        recommend_num.setText(pRecommend + "张");
        gold_num.setText(pGold + "张");
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        params.rightMargin = (int)(money.getTextSize() * 2.5);
        params.addRule(RelativeLayout.CENTER_VERTICAL);

        money.setLayoutParams(params);
        notes_num.setLayoutParams(params);
        vip_num.setLayoutParams(params);
        grow_num.setLayoutParams(params);
        recommend_num.setLayoutParams(params);
        gold_num.setLayoutParams(params);
        drawable_back_tv = new BitmapDrawable(PublicUtil.getAlphaBitmap(PublicUtil.readBitMap(mContext,R.drawable.lk_back_small),Color.parseColor("#66ccdd")));
        back_tv.setImageDrawable(drawable_back_tv);
        drawable_right_jiantou = new BitmapDrawable(PublicUtil.getAlphaBitmap(PublicUtil.readBitMap(mContext,R.drawable.lk_enter_small),Color.parseColor("#cccccc")));
        reader_right.setImageDrawable(drawable_right_jiantou);
        vip_right.setImageDrawable(drawable_right_jiantou);
        grow_right.setImageDrawable(drawable_right_jiantou);
        chongzhi_right.setImageDrawable(drawable_right_jiantou);
        consume_right.setImageDrawable(drawable_right_jiantou);
        change_right.setImageDrawable(drawable_right_jiantou);
    }

    @Override
    protected void setListener() {
        rela_recharge.setOnClickListener(this);
        rela_consume.setOnClickListener(this);
        rela_notes.setOnClickListener(this);
        rela_vip.setOnClickListener(this);
        rela_grow.setOnClickListener(this);
        rela_recommend.setOnClickListener(this);
        rela_gold.setOnClickListener(this);
        rela_change.setOnClickListener(this);
//        recharge_btn.setOnClickListener(this);
        back_layout.setOnClickListener(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (SPUtil.getBoolean("switch_account", false)) {
            SPUtil.putBoolean("switch_account", false);
            finish();
        }
    }

    @Override
    protected void onClickEvent(View view) {
        switch (view.getId()) {
            case R.id.back_layout: //返回
                finish();
                break;
            case R.id.rela_recharge: // 充值记录
                Intent intent = new Intent(mContext, PersonalRecharge.class);
                startActivity(intent);
                break;
            case R.id.rela_consume: // 消费记录
                Intent intent1 = new Intent(mContext, PersonalConsume.class);
                startActivity(intent1);
                break;
            //            case R.id.recharge_btn: // 立即充值
            //                startActivity(new Intent(mContext, RechargePage.class).putIntegerArrayListExtra("payratio", payratio).putExtra("payAction", pPayAction));
            //                break;
            case R.id.rela_notes: // 阅读券
                startActivity(new Intent(mContext, ReadTicketActivity.class));
                break;
            case R.id.rela_vip: // VIP等级
                startActivity(new Intent(mContext, WebViewActivity.class).putExtra("mHtmlUrl", APIProtocol.getRootURL() + "qa#weal").putExtra("title", "vip等级"));
                break;
            case R.id.rela_grow: // 成长值
                startActivity(new Intent(mContext, WebViewActivity.class).putExtra("mHtmlUrl", APIProtocol.getRootURL() + "qa#VIP").putExtra("title", "成长值"));
                break;
            case R.id.rela_recommend: // 推荐票
                startActivity(new Intent(mContext, WebViewActivity.class).putExtra("mHtmlUrl", APIProtocol.getRootURL() + "qa#ticket").putExtra("title", "推荐票"));
                break;
            case R.id.rela_gold: //黄金联赛票
                startActivity(new Intent(mContext, WebViewActivity.class).putExtra("mHtmlUrl", APIProtocol.getRootURL() + "qa#gold").putExtra("title", "黄金联赛票"));
                break;
            case R.id.rela_change: // 切换账号
                startActivity(new Intent(mContext, LoginActivity.class));
                break;
            default:
                break;
        }
    }
}
